﻿#include "stdafx.h"
#include "TitleBar.h"
#include "ToolButton.h"
#include "ui_TitleBar.h"

#include <QMouseEvent>

TitleBar::TitleBar(QWidget *parent)
: QWidget(parent), ui(new Ui::TitleBar)
{
	ui->setupUi(this);
	initUI();
}

TitleBar::~TitleBar()
{
	delete ui;
}

/***********************************************************************************************************************************/
void TitleBar::initUI()
{
	ui->btnMin->setVisible(true);
	ui->btnMax->setVisible(true);
	ui->btnClose->setVisible(true);
}

void TitleBar::initData()
{
	
}

void TitleBar::initConnect()
{

}

QAbstractButton * TitleBar::getMaxBtn()
{
	return ui->btnMax;
}

QAbstractButton * TitleBar::getMinBtn()
{
	return ui->btnMin;
}

QAbstractButton * TitleBar::getCloseBtn()
{
	return ui->btnClose;
}

/***********************************************************************************************************************************/
void TitleBar::setTitleText(const QString & title)
{
	ui->labTitle->setText(title);
}

void TitleBar::setBtnVisible(QAbstractButton * btn, bool visible)
{
	btn->setVisible(visible);
}

QRect TitleBar::getDoubleClickResponseRect()
{
	QRect rectCur = this->rect();
	QPoint leftUpGlobalPoint = mapToGlobal(rectCur.topLeft()); 
	QPoint minPoint = mapToGlobal(ui->btnMin->pos());

	return QRect(leftUpGlobalPoint.x(), leftUpGlobalPoint.y(),minPoint.x(), rectCur.height());
}

